#ifndef DAILYOPERATIONSDBTEMP_H
#define DAILYOPERATIONSDBTEMP_H

#include "CoreFarmAPI.h"

typedef struct DailyOperationsNode{
	char userName[USERNAME_LENGTH];
	int serverID;
	char operation[OPERATION_LENGTH];
	struct DailyOperationsNode *next;

}DailyOperationsNode;

DailyOperationsNode* dailyOperationsNodeConstructor(){
	DailyOperationsNode *thisNode;
	thisNode = (DailyOperationsNode*)malloc(sizeof(DailyOperationsNode));
	assertMem(thisNode);

	thisNode->next = NULL;
	thisNode->serverID = 0;
	return thisNode;
}
void dailyOperationsNodeSetUserName(DailyOperationsNode *thisNode, char *userName){ strcpy(thisNode->userName, userName); }
void dailyOperationsNodeSetServerID(DailyOperationsNode *thisNode, int serverID){ thisNode->serverID = serverID; }
void dailyOperationsNodeSetOperation(DailyOperationsNode *thisNode, char *operation){ strcpy(thisNode->operation, operation); }
void dailyOperationsNodeSetNext(DailyOperationsNode *thisNode, DailyOperationsNode *_next){ thisNode->next = _next; }

char* dailyOperationsNodeGetUserName(DailyOperationsNode *thisNode){ return (thisNode)?thisNode->userName:NULL; }
int dailyOperationsNodeGetServerID(DailyOperationsNode *thisNode){ return (thisNode)?thisNode->serverID:NULL; }
char* dailyOperationsNodeGetOperation(DailyOperationsNode *thisNode){ return (thisNode)?thisNode->operation:NULL; }
DailyOperationsNode* dailyOperationsNodeGetNext(DailyOperationsNode *thisNode){ return (thisNode)?thisNode->next:NULL; }

typedef struct DailyOperationsDB{
	DailyOperationsNode *head;
	int size;
}DailyOperationsDB;
DailyOperationsDB *dailyOperations_DB = NULL;

void dailyOperationsDBConstructor(){
	dailyOperations_DB = (DailyOperationsDB*)malloc(sizeof(DailyOperationsDB));
	assertMem(dailyOperations_DB);

	dailyOperations_DB->size = 0;
	dailyOperations_DB->head = NULL;
}
DailyOperationsNode* dailyOperationsDBGetHead(){ return (dailyOperations_DB)?dailyOperations_DB->head : NULL; }

int dailyOperationsDBIsEmpty(){ return (dailyOperations_DB->size==0); }

void dailyOperationsDBPush( char *userName, int serverID, char *operation){
	DailyOperationsNode *newDailyOperations = dailyOperationsNodeConstructor();

	dailyOperationsNodeSetUserName( newDailyOperations, userName);
	dailyOperationsNodeSetServerID( newDailyOperations, serverID);
	dailyOperationsNodeSetOperation( newDailyOperations, operation);

	if ( !dailyOperations_DB )
		dailyOperationsDBConstructor();

	if( !dailyOperationsDBIsEmpty() )
		newDailyOperations->next = dailyOperations_DB->head;

	dailyOperations_DB->head = newDailyOperations;
	dailyOperations_DB->size++;
}

void dailyOperationsDBPrintAll(){

	DailyOperationsNode *currNode = dailyOperationsDBGetHead();

	while(currNode)
	{
		fprintf(stdout,"User:%s. Id:%d, Op:%s\n", currNode->userName, currNode->serverID, currNode->operation);
		currNode = currNode->next;
	}
}

#endif